home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / flex_247.zip / flex_247 / FlexLexer.h < prev    next >
C/C++ Source or Header  |  1994-01-04  |  5KB  |  176 lines

  1. // $Header: FlexLexer.h,v 1.2 94/01/04 14:57:26 vern Exp $
  2.  
  3. // FlexLexer.h -- define classes for lexical analyzers generated by flex
  4.  
  5. // Copyright (c) 1993 The Regents of the University of California.
  6. // All rights reserved.
  7. //
  8. // This code is derived from software contributed to Berkeley by
  9. // Kent Williams and Tom Epperly.
  10. //
  11. // Redistribution and use in source and binary forms are permitted provided
  12. // that: (1) source distributions retain this entire copyright notice and
  13. // comment, and (2) distributions including binaries display the following
  14. // acknowledgement:  ``This product includes software developed by the
  15. // University of California, Berkeley and its contributors'' in the
  16. // documentation or other materials provided with the distribution and in
  17. // all advertising materials mentioning features or use of this software.
  18. // Neither the name of the University nor the names of its contributors may
  19. // be used to endorse or promote products derived from this software without
  20. // specific prior written permission.
  21. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  22. // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  23. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24.  
  25. #ifndef __FLEX_LEXER_H
  26. #define __FLEX_LEXER_H
  27.  
  28.  
  29. // This file defines two classes.  The first, FlexLexer, is an abstract
  30. // class which specifies the external interface provided to flex C++
  31. // lexer objects.  The second, yyFlexLexer, fills out most of the meat
  32. // of the lexer class; its internals may vary from lexer to lexer
  33. // depending on things like whether REJECT is used.
  34. //
  35. // If you want to create multiple lexer classes, you use the -P flag
  36. // to rename each yyFlexLexer to some other xxFlexLexer.
  37.  
  38. #include <iostream.h>
  39.  
  40. extern "C++" {
  41.  
  42. struct yy_buffer_state;
  43. typedef int yy_state_type;
  44.  
  45. class FlexLexer {
  46. public:
  47.     virtual ~FlexLexer()    { }
  48.  
  49.     const char* YYText()    { return yytext; }
  50.     int YYLeng()        { return yyleng; }
  51.  
  52.     virtual void
  53.         yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
  54.     virtual struct yy_buffer_state*
  55.         yy_create_buffer( istream* s, int size ) = 0;
  56.     virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
  57.     virtual void yyrestart( istream* s ) = 0;
  58.  
  59.     virtual int yylex() = 0;
  60.  
  61. protected:
  62.     char* yytext;
  63.     int yyleng;
  64. };
  65.  
  66.  
  67. class yyFlexLexer : public FlexLexer {
  68. public:
  69.     // arg_yyin and arg_yyout default to the cin and cout, but we
  70.     // only make that assignment when initializing in yylex().
  71.     yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
  72.         {
  73.         yyin = arg_yyin;
  74.         yyout = arg_yyout;
  75.         yy_c_buf_p = 0;
  76.         yy_init = 1;
  77.         yy_start = 0;
  78.  
  79.         yy_did_buffer_switch_on_eof = 0;
  80.  
  81.         yy_looking_for_trail_begin = 0;
  82.         yy_more_flag = 0;
  83.         yy_more_len = 0;
  84.  
  85.         yy_start_stack_ptr = yy_start_stack_depth = 0;
  86.         yy_start_stack = 0;
  87.  
  88.         yy_current_buffer = 0;
  89.  
  90. #ifdef YY_USES_REJECT
  91.         yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
  92. #else
  93.         yy_state_buf = 0;
  94. #endif
  95.         }
  96.  
  97.     virtual ~yyFlexLexer()
  98.         {
  99.         delete yy_state_buf;
  100.         }
  101.  
  102.     void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
  103.     struct yy_buffer_state* yy_create_buffer( istream* s, int size );
  104.     void yy_delete_buffer( struct yy_buffer_state* b );
  105.     void yyrestart( istream* s );
  106.  
  107.     virtual int yylex();
  108.  
  109. protected:
  110.     virtual int LexerInput( char* buf, int max_size );
  111.     virtual void LexerOutput( const char* buf, int size );
  112.     virtual void LexerError( const char* msg );
  113.  
  114.     void yyunput( int c, char* buf_ptr );
  115.     int yyinput();
  116.  
  117.     void yy_load_buffer_state();
  118.     void yy_init_buffer( struct yy_buffer_state* b, istream* s );
  119.  
  120.     int yy_start_stack_ptr;
  121.     int yy_start_stack_depth;
  122.     int* yy_start_stack;
  123.  
  124.     void yy_push_state( int new_state );
  125.     void yy_pop_state();
  126.     int yy_top_state();
  127.  
  128.     yy_state_type yy_get_previous_state();
  129.     yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  130.     int yy_get_next_buffer();
  131.  
  132.     istream* yyin;    // input source for default LexerInput
  133.     ostream* yyout;    // output sink for default LexerOutput
  134.  
  135.     struct yy_buffer_state* yy_current_buffer;
  136.  
  137.     // yy_hold_char holds the character lost when yytext is formed.
  138.     char yy_hold_char;
  139.  
  140.     // Number of characters read into yy_ch_buf.
  141.     int yy_n_chars;
  142.  
  143.     // Points to current character in buffer.
  144.     char* yy_c_buf_p;
  145.  
  146.     int yy_init;        // whether we need to initialize
  147.     int yy_start;        // start state number
  148.  
  149.     // Flag which is used to allow yywrap()'s to do buffer switches
  150.     // instead of setting up a fresh yyin.  A bit of a hack ...
  151.     int yy_did_buffer_switch_on_eof;
  152.  
  153.     // The following are not always needed, but may be depending
  154.     // on use of certain flex features (like REJECT or yymore()).
  155.  
  156.     yy_state_type yy_last_accepting_state;
  157.     char* yy_last_accepting_cpos;
  158.  
  159.     yy_state_type* yy_state_buf;
  160.     yy_state_type* yy_state_ptr;
  161.  
  162.     char* yy_full_match;
  163.     int* yy_full_state;
  164.     int yy_full_lp;
  165.  
  166.     int yy_lp;
  167.     int yy_looking_for_trail_begin;
  168.  
  169.     int yy_more_flag;
  170.     int yy_more_len;
  171. };
  172.  
  173. }
  174.  
  175. #endif
  176.